package net.xuzhen97.distributed.transaction.course.adpter.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.xuzhen97.distributed.transaction.course.common.Constant;
import net.xuzhen97.distributed.transaction.course.common.util.UserUtil;
import net.xuzhen97.distributed.transaction.course.service.OpenCourseService;
import net.xuzhen97.distributed.transaction.course.service.dto.OpenCourseCmd;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Api(tags = "开通课程")
public class OpenCourseController {

    @Resource
    private OpenCourseService openCourseService;

    @ApiOperation(
            value = "开通课程"
    )
    @PostMapping("/open-course")
    @ApiImplicitParam(paramType = "header", name = Constant.HEADER_CURRENT_USER_ID, value = "当前用户Id", dataType = "string", required = true)
    public ResponseEntity<?> openCourse(@RequestBody OpenCourseCmd cmd){
        cmd.setOpUserId(UserUtil.getCurrentUserId());
        String id = openCourseService.openCourse(cmd);
        return ResponseEntity.status(HttpStatus.CREATED).body(id);
    }
}
